export const HOOKS = [
    'beforeCreate', 'created', 'beforeMount', 'mounted', 'beforeUpdate', 'updated', 'deforeDestroy', 'destroyed'
]

const starts = {}
starts.data = function (parentVal, childVal) {
    return childVal
}
// todo
// starts.computed = function () { }
// starts.watch = function () { }
// starts.methods = function () { }
starts.components = function (parentVal, childVal) {
    const obj = Object.create(parentVal)
    if (childVal) {
        for (let key in childVal) {
            obj[key] = childVal[key]
        }
    }
    return obj
}

HOOKS.forEach(hook => {
    starts[hook] = mergeHook
})
function mergeHook(parentVal, childVal) {
    if (childVal) {
        if (parentVal) {
            return parentVal.concat(childVal)
        } else {
            return [childVal]
        }
    } else {
        return parentVal
    }
}

export function mergeOptions(parent, child) {
    const options = {}
    for (const key in parent) {
        mergeField(key)
    }
    for (const key in child) {
        mergeField(key)
    }

    function mergeField(key) {
        if (starts[key]) {
            options[key] = starts[key](parent[key], child[key])
        } else {
            options[key] = child[key] || parent[key]
        }
    }

    return options
}